package typechecker.ast.type;

import java.util.HashMap;
import java.util.Map;

import typechecker.Stage;
import typechecker.ast.Context;
import typechecker.ast.InductiveDatatype;

/**
 * Type constructors have different instances at each occurence (having diferent size annotations).
 * Type cosntructors are somewhat stage polymorphic.
 */
public class TypeConstructor extends TypeVariable{
	private static Map<String , InductiveDatatype> idts = new HashMap<String, InductiveDatatype>();
	private boolean starred;
	private Stage stage = Stage.INFINITY;
	
	public TypeConstructor(String name) {
		super(name);
	}
	
	public void setStarred() {
		starred = true;
	}
	
	public boolean isStarred() {
		return starred;
	}

	public void setStage(Stage stage) {
		this.stage = stage;
	}
	
	public Stage getStage() {
		return stage;
	}
	
	public InductiveDatatype getIdt() {
		return idts.get(this.name);
	}
	
	public void setIdt(InductiveDatatype idt) {
		idts.put(this.name, idt);
	}

	@Override
	public String preetyPrint() {
		return this.name+"_"+stage.preetyPrint();
	}
	
	@Override
	public String getName() {
		return super.getName();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof TypeConstructor){
			TypeConstructor tc = (TypeConstructor) obj;
			return tc.name.equals(name);
		}
		return false;
	}

	@Override
	public String toString() {
		return this.name;
	}
	
	@Override
	public TypeExpression freshCopy(Context<TypeVariable> ctx) {
		TypeConstructor ret =  new TypeConstructor(this.name);
		ret.starred = this.starred;
		ret.stage = this.stage;
		return ret;
	}
}
